package work.skc.trad;

import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.alibaba.excel.EasyExcel;
import lombok.SneakyThrows;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

/**
 * @author Gong.Yang
 */
public class Demo {
    @SneakyThrows
    public static void main(String[] args) {
        String filePrefix = "E:\\work-records\\louis\\l-skc trad数据导出\\";
        String fileName = filePrefix + "中间数据";
        FileInputStream inputStream = new FileInputStream(fileName + ".txt");

        BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
        String line;
        List<JSONObject> list = new ArrayList<>();
        while ((line = reader.readLine()) != null) {
            JSONObject json = JSONUtil.parseObj(line);
            list.add(json);
        }

        List<ExcelEntity> excelEntities = new ArrayList<>();
        for (JSONObject json : list) {
            ExcelEntity deliverInfo = json.getJSONObject("middleExchangeSyncOrderRequest").get("deliverInfo", ExcelEntity.class);
            excelEntities.add(deliverInfo);
        }

        EasyExcel.write(fileName + ".xlsx").sheet("sheet1").doWrite(excelEntities);

    }
}
